package com.it.test;


import com.it.config.SpringConfig;
import com.it.config.controller.spring_04_ioc_note;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class spring_04_text {
    /*
     * 【测试】：基于注解的方式管理 Bean
     * */

    // 测试：组件（Bean）的获取 (XML配置类 + 注解)
    @Test
    public void test01() {
        ClassPathXmlApplicationContext cpx = new ClassPathXmlApplicationContext("spring_ioc_04.xml");

        spring_04_ioc_note cpxBean = cpx.getBean(spring_04_ioc_note.class);

        System.out.println(cpxBean.toString());

        cpxBean.getSpring01IocXml().method();

        cpxBean.method();

        cpx.close();
    }

    // 测试：组件（Bean）的获取 (Java配置类 + 注解)
    @Test
    public void test02() {
        AnnotationConfigApplicationContext ann = new AnnotationConfigApplicationContext(SpringConfig.class);
        spring_04_ioc_note annBean = ann.getBean(spring_04_ioc_note.class);
        spring_04_ioc_note annBean1 = ann.getBean(spring_04_ioc_note.class);

        // 作用域
        System.out.println(annBean == annBean1);

        System.out.println(annBean.toString());

        annBean.getSpring01IocXml().method();

        annBean.method();
        ann.close();

    }


}
